package com.xinyun.server;

import io.netty.channel.Channel;

import java.util.*;

/**
 * Created by bubusy on 16/5/22.
 */
public class ChannelManager {
    private static ChannelManager instance = null;

    private static Map<String, Session> channels = new HashMap<String, Session>();


    public static void addChannel(Channel channel) {
        String key = channel.id().toString();
        Session session = new Session(key, channel, null);
        channels.put(key, session);
    }

    public static Map<String, Session> getChannels() {
        return channels;
    }

    public static void updateChannelBoardId(Channel channel, String boardId) {
        Session target = channels.get(channel.id().toString());
        if (target != null) {
            target.boardId = boardId;
        }
    }

    public static String getBoardIdByChannel(Channel channel) {
        Session target = channels.get(channel.id().toString());
        if (target != null) {
            return target.boardId;
        } else {
            return null;
        }
    }
}
